/**
 * 前端通用枚举定义
 * 用于替代代码中的魔法字符串，提高代码可维护性
 */

/**
 * 题目类型枚举
 */
export enum QuestionType {
  /** 单选题 */
  SINGLE = 'single',
  /** 多选题 */
  MULTIPLE = 'multiple',
  /** 判断题 */
  JUDGE = 'judge'
}

/**
 * 题目类型显示文本映射
 */
export const QuestionTypeText = {
  [QuestionType.SINGLE]: '单选题',
  [QuestionType.MULTIPLE]: '多选题',
  [QuestionType.JUDGE]: '判断题'
} as const;

/**
 * 难度级别枚举
 */
export enum DifficultyLevel {
  /** 简单 */
  EASY = 'easy',
  /** 中等 */
  MEDIUM = 'medium',
  /** 困难 */
  HARD = 'hard',
  /** 高级 */
  ADVANCED = 'advanced'
}

/**
 * 难度级别显示文本映射
 */
export const DifficultyLevelText = {
  [DifficultyLevel.EASY]: '简单',
  [DifficultyLevel.MEDIUM]: '中等',
  [DifficultyLevel.HARD]: '困难',
  [DifficultyLevel.ADVANCED]: '高级'
} as const;

/**
 * 考试状态枚举
 */
export enum ExamStatus {
  /** 已完成 */
  COMPLETED = 'completed',
  /** 已放弃 */
  ABANDONED = 'abandoned',
  /** 进行中 */
  IN_PROGRESS = 'in_progress'
}

/**
 * 考试状态显示文本映射
 */
export const ExamStatusText = {
  [ExamStatus.COMPLETED]: '已完成',
  [ExamStatus.ABANDONED]: '已放弃',
  [ExamStatus.IN_PROGRESS]: '进行中'
} as const;

/**
 * 趋势方向枚举
 */
export enum TrendDirection {
  /** 上升 */
  UP = 'up',
  /** 下降 */
  DOWN = 'down',
  /** 稳定 */
  STABLE = 'stable'
}

/**
 * 趋势方向显示文本映射
 */
export const TrendDirectionText = {
  [TrendDirection.UP]: '上升趋势',
  [TrendDirection.DOWN]: '下降趋势',
  [TrendDirection.STABLE]: '稳定'
} as const;

/**
 * 分数等级枚举
 */
export enum ScoreLevel {
  /** 优秀 (90-100) */
  EXCELLENT = 'excellent',
  /** 良好 (80-89) */
  GOOD = 'good',
  /** 及格 (60-79) */
  PASS = 'pass',
  /** 不及格 (0-59) */
  FAIL = 'fail'
}

/**
 * 分数等级配置
 */
export const ScoreLevelConfig = {
  [ScoreLevel.EXCELLENT]: {
    min: 90,
    max: 100,
    text: '优秀',
    emoji: '🎉',
    comment: '太棒了！',
    encouragement: '恭喜你！已经掌握得非常好了，继续保持！'
  },
  [ScoreLevel.GOOD]: {
    min: 80,
    max: 89,
    text: '良好',
    emoji: '😊',
    comment: '很不错！',
    encouragement: '做得很好！再接再厉，向满分冲刺！'
  },
  [ScoreLevel.PASS]: {
    min: 60,
    max: 79,
    text: '及格',
    emoji: '😐',
    comment: '还需努力！',
    encouragement: '继续努力！多做练习，一定能提高！'
  },
  [ScoreLevel.FAIL]: {
    min: 0,
    max: 59,
    text: '不及格',
    emoji: '😔',
    comment: '加油！',
    encouragement: '不要气馁！重新学习知识点，再来挑战！'
  }
} as const;

/**
 * 根据分数获取分数等级
 * @param score 分数 (0-100)
 * @returns 分数等级
 */
export function getScoreLevel(score: number): ScoreLevel {
  if (score >= 90) return ScoreLevel.EXCELLENT;
  if (score >= 80) return ScoreLevel.GOOD;
  if (score >= 60) return ScoreLevel.PASS;
  return ScoreLevel.FAIL;
}

/**
 * 根据分数获取分数等级配置
 * @param score 分数 (0-100)
 * @returns 分数等级配置
 */
export function getScoreLevelConfig(score: number) {
  const level = getScoreLevel(score);
  return ScoreLevelConfig[level];
}

/**
 * 检查是否为有效的题目类型
 * @param type 题目类型字符串
 * @returns 是否为有效类型
 */
export function isValidQuestionType(type: string): type is QuestionType {
  return Object.values(QuestionType).includes(type as QuestionType);
}

/**
 * 检查是否为有效的难度级别
 * @param difficulty 难度级别字符串
 * @returns 是否为有效难度
 */
export function isValidDifficultyLevel(difficulty: string): difficulty is DifficultyLevel {
  return Object.values(DifficultyLevel).includes(difficulty as DifficultyLevel);
}
